﻿using System;
using System.Web.Mvc;

namespace Avalon.Core.MVC.Attributes
{
    [AttributeUsage(AttributeTargets.Property)]
    public class ParentAttribute : Attribute, IMetadataAware
    {
        public const string Key = "ParentKey";
        public string ParentEntityName { get; set; }

        public ParentAttribute()
        {
            ParentEntityName = "";
        }

        public ParentAttribute(string parentEntityName)
        {
            ParentEntityName = parentEntityName;
        }

        public void OnMetadataCreated(ModelMetadata metadata)
        {
            metadata.AdditionalValues[Key] = this.ParentEntityName;
        }
    }
}
